﻿#include "log_textbrowser.h"
#include <QtCore/QFileInfo>
#include <QtGui/QDesktopServices>

#include "my_log.h"

#ifdef Q_CC_MSVC
#pragma execution_character_set("utf-8")
#endif

LogTextBrowser::LogTextBrowser(QWidget* parent /*= Q_NULLPTR*/) : QTextBrowser
(parent)
{
	//绑定信号，将调试信息输出值ui
	//connect(MyLog::Instance(), &MyLog::sigDebugStrData, this, &Log_TextBrowser::append);

	setOpenLinks(false);
	setOpenExternalLinks(false);


	setFont(QFont("宋体", 13, 3));


    //connect(MyLog::Instance(), &MyLog::sigDebugHtmlData, this, &LogTextBrowser::append);

	QMetaObject::Connection con =
		connect(this, &QTextBrowser::anchorClicked, [=](const QUrl& link)
			{
				auto path = link.path();
				QFileInfo info(path);

				if (info.isDir())
					QDesktopServices::openUrl(link);
				else if (info.isFile())
					QDesktopServices::openUrl(QUrl::fromLocalFile(path));
				//ShellExecute(NULL, "open", "notepad++", path.toLocal8Bit(), "", true);
			});
}

LogTextBrowser::~LogTextBrowser()
{

}

void LogTextBrowser::append(const QString& text)
{
	QTextEdit::append(text);
}

QSize LogTextBrowser::sizeHint()
{
	return QSize(100, 200);
}
